package ajax17;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class LoginServlet
 */
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userid;
		String pw1;
										
		if (request.getParameter("userid") != null && request.getParameter("pw1") != null ){
			userid = request.getParameter("userid");
			pw1 = request.getParameter("pw1");
								
			//mem_login m = new mem_login(userid, pw1);
			mem_login m = new mem_login(userid, pw1);
			HttpSession session = request.getSession();
			session.setAttribute("m", m);
			
			if (m.login()){
				// 註冊成功
				//response.sendRedirect("login_success.jsp");
				response.sendRedirect("login_success.jsp");
			}else{
				//
				response.sendRedirect("login.jsp");
			}
			System.out.println("m.return_time = " + m.getReturn_time());
		}
	}

}
